<template>
  <div id="app">
    <router-view />
  </div>
</template>
<script>
import { getItem, setItem, removeItem } from '@/utils/storage'

import bus from '@/utils/bus'
export default {
  name: 'App',
  mounted() {
    bus.$on('open-collection', isRender => {
      setItem('COllECT_TIME_LIMIT', Date.now() + 300000)
      setTimeout(() => {
        this.openCollection(isRender)
      }, 500)
    })
  },
  methods: {
    openCollection(flag) {
      const { collectTimeLimit } = getItem('COllECT_TIME_LIMIT')
      // 首先判断 canPop 是否为 true   true(可谈)   false(不可谈)
      const { isPop } = this.$store.state.collectObj
      if (!isPop) return
      // / * 判断 当前时间与 collectionTimeLimit 对比,  此处有问题 。。。
      // 如果 一开始没有 collectionTimeLimit ， 那么 此时 说明是 可进行弹窗的
      // 若 “此时” > collectionTimeLimit 重置 count, 但不重置 canPop，
      // “此时” < collectionTimeLimit return * /
      const dateString = Date.now()
      if (!collectTimeLimit) {
        this.doRender(flag)
      } else if (dateString < collectTimeLimit) {
        this.doRender(false)
      } else if (dateString > collectTimeLimit) {
        const collectObj = getItem('COLLECT_OBJ')
        collectObj.swiper = 0
        collectObj.less = 0
        collectObj.router = 0
        this.$store.commit('changeState', { key: 'collectObj', value: collectObj })
        setItem('COLLECT_OBJ', collectObj)
        removeItem('COllECT_TIME_LIMIT')
      } else {
        this.doRender(flag)
      }
    },
    doRender(flag) {
      console.log('flag ===>', flag)
    }
  },
  destroyed: function() {
    bus.off('open-collection')
  }
}
</script>
<style></style>
